package com.ruoyi.video.service.impl;

import com.ruoyi.video.domain.BusMemberInfo;
import com.ruoyi.video.domain.dto.PromDetailDTO;
import com.ruoyi.video.domain.vo.LoginParam;
import com.ruoyi.video.mapper.MemberInfoMapper;
import com.ruoyi.video.service.IMemberInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberInfoServiceImpl implements IMemberInfoService {

    @Autowired
    private MemberInfoMapper memberInfoMapper;

    @Override
    public BusMemberInfo selectMemberById(String memberId) {
        return memberInfoMapper.selectMemberById(memberId);
    }

    @Override
    public BusMemberInfo selectMemberByIp(String memberIp) {
        return memberInfoMapper.selectMemberByIp(memberIp);
    }

    @Override
    public BusMemberInfo selectMemberByPromCode(String promCode) {
        return memberInfoMapper.selectMemberByPromCode(promCode);
    }

    @Override
    public List<BusMemberInfo> selectMemberList(BusMemberInfo memberInfo) {
        return memberInfoMapper.selectMemberList(memberInfo);
    }

    @Override
    public List<BusMemberInfo> selectMemberListByPId(String pMemberId) {
        return memberInfoMapper.selectMemberListByPId(pMemberId);
    }

    @Override
    public List<BusMemberInfo> selectMemberListByPIdAndIp(String pMemberId, String memberIp) {
        return memberInfoMapper.selectMemberListByPIdAndIp(pMemberId, memberIp);
    }

    @Override
    public int insertMember(BusMemberInfo memberInfo) {
        return memberInfoMapper.insertMember(memberInfo);
    }

    @Override
    public int updateMember(BusMemberInfo memberInfo) {
        return memberInfoMapper.updateMember(memberInfo);
    }

    @Override
    public int deleteMemberByIds(String[] memberIds) {
        return memberInfoMapper.deleteMemberByIds(memberIds);
    }

    @Override
    public List<PromDetailDTO> selectPromStatisticsByPMemberId(String pMemberId, int rebatePercent) {
        List<PromDetailDTO> detailDTOList = memberInfoMapper.selectPromStatisticsByPMemberId(pMemberId);
        for (PromDetailDTO detailDTO : detailDTOList) {
            int originalPrice = detailDTO.getPromPackageBeAmount();
            String result = String.format("%.2f", (float) originalPrice / (float) 100 * rebatePercent);
            detailDTO.setPromPackageAfAmount(result);
        }
        return detailDTOList;
    }
}
